<?php

namespace App\Service\Cruise\Check;

use App\Service\BaseService;
use App\Service\Common\SmsService;
use Illuminate\Support\Facades\Log;
use Overtrue\EasySms\Exceptions\InvalidArgumentException;

class CruiseCheckSmsService extends BaseService
{
    /**
     * 巡检任务发送短信
     *  模版内容： 您有${num}条${mission}任务${doName}！
     * 【夸父供应商】您有1条任务【测试-生物防治版5月】待处理！
     *
     * @param string $mobile
     * @param int $taskNum x 条任务
     * @param string $taskName 测试-生物防治版5月
     * @param string $taskStatus 待处理/待初审/已驳回，请立即修改
     * @param string $missionName 任务类型 比如说 转交任务
     * @return void
     * @throws InvalidArgumentException
     */
    public static function sendInspectionTask(
        string $mobile,
        int $taskNum = 1,
        string $taskName = '',
        string $taskStatus = '',
        string $missionName = ''
    ) {
        $template = 'SMS_467055147';

        $doName = vsprintf("%s%s", [
            $taskName,
            $taskStatus
        ]);
        $data   = [
            'num'     => $taskNum,
            'doName'  => $doName,
            'mission' => $missionName
        ];

        try {
            self::baseSend($mobile, $template, $data);
        } catch (\Exception $e) {
            Log::warning($e);
        }
    }


    /**
     * @throws InvalidArgumentException
     */
    private static function baseSend(string $mobile, string $template, array $data)
    {
        (new SmsService())->aliyunSend($mobile, $template, $data, config('sms.signSupplyName'));
    }
}
